grammar Hello;

r:   expr ;

expr returns [int value]
    :   e=term {$value = $e.value;}
        (   '+' e=term {$value += $e.value;}
        |   '-' e=term {$value -= $e.value;}
        )*
    ;

term returns [int value]
    :   e=factor {$value = $e.value;} ('*' e=factor {$value *= $e.value;})*
    ; 

factor returns [int value]
    :   INT {$value = Integer.parseInt($INT.text);}
    |   '(' expr ')' {$value = $expr.value;}
    ;

INT :   '0'..'9'+ ;
WS  :   (' '|'\t')+ {skip();} ;